package com.liujit.bms.pc.controller;

import com.liujit.bms.pc.domain.result.BlogArticleResult;
import com.liujit.bms.pc.domain.result.BlogLabelResult;
import com.liujit.bms.pc.service.BlogArticleLabelService;
import com.liujit.bms.pc.service.BlogArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @Description 博客文章管理接口
 * @Author liujun
 * @Date 2021-07-03 14:55:02
 */
@RequiredArgsConstructor
@Api(tags = "博客文章管理接口")
@Controller
@RequestMapping("/blog/article")
public class BlogArticleController {

    private final BlogArticleService blogArticleService;

    private final BlogArticleLabelService blogArticleLabelService;

    @ApiOperation(value = "查询", notes = "根据博客文章id，查询博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "博客文章id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/{id}")
    public String get(Model model, @PathVariable Long id) {
        // 文章信息
        BlogArticleResult blogArticle = blogArticleService.get(id);
        model.addAttribute("article", blogArticle);
        // 标签
        List<BlogLabelResult> label = blogArticleLabelService.getListByArticleId(id);
        model.addAttribute("label", label);
        // 获取上一篇
        Map<String, Object> up = blogArticleService.getUp(blogArticle.getUpdateTime());
        model.addAttribute("up", up);
        // 获取下一篇
        Map<String, Object> down = blogArticleService.getDown(blogArticle.getUpdateTime());
        model.addAttribute("down", down);
        return "page";
    }
}
